package com.monitor.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.monitor.common.annotation.Log;
import com.monitor.common.core.controller.BaseController;
import com.monitor.common.core.domain.AjaxResult;
import com.monitor.common.enums.BusinessType;
import com.monitor.system.domain.LinkTopology;
import com.monitor.system.service.ILinkTopologyService;
import com.monitor.common.utils.poi.ExcelUtil;
import com.monitor.common.core.page.TableDataInfo;

/**
 * 链路拓扑Controller
 * 
 * @author monitor
 * @date 2024-06-06
 */
@RestController
@RequestMapping("/system/topology")
public class LinkTopologyController extends BaseController
{
    @Autowired
    private ILinkTopologyService linkTopologyService;

    /**
     * 查询链路拓扑列表
     */
    @ApiOperation("查询链路拓扑列表")
    @PreAuthorize("@ss.hasPermi('system:topology:list')")
    @GetMapping("/list")
    public TableDataInfo list(LinkTopology linkTopology)
    {
        startPage();
        List<LinkTopology> list = linkTopologyService.selectLinkTopologyList(linkTopology);
        return getDataTable(list);
    }

    /**
     * 导出链路拓扑列表
     */
    @ApiOperation("导出链路拓扑列表")
    @PreAuthorize("@ss.hasPermi('system:topology:export')")
    @Log(title = "链路拓扑", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LinkTopology linkTopology)
    {
        List<LinkTopology> list = linkTopologyService.selectLinkTopologyList(linkTopology);
        ExcelUtil<LinkTopology> util = new ExcelUtil<LinkTopology>(LinkTopology.class);
        util.exportExcel(response, list, "链路拓扑数据");
    }

    /**
     * 获取链路拓扑详细信息
     */
    @ApiOperation("获取链路拓扑详细信息")
    @PreAuthorize("@ss.hasPermi('system:topology:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(linkTopologyService.selectLinkTopologyById(id));
    }

    /**
     * 新增链路拓扑
     */
    @ApiOperation("新增链路拓扑")
    @PreAuthorize("@ss.hasPermi('system:topology:add')")
    @Log(title = "链路拓扑", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LinkTopology linkTopology)
    {
        return toAjax(linkTopologyService.insertLinkTopology(linkTopology));
    }

    /**
     * 修改链路拓扑
     */
    @ApiOperation("修改链路拓扑")
    @PreAuthorize("@ss.hasPermi('system:topology:edit')")
    @Log(title = "链路拓扑", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LinkTopology linkTopology)
    {
        return toAjax(linkTopologyService.updateLinkTopology(linkTopology));
    }

    /**
     * 删除链路拓扑
     */
    @ApiOperation("删除链路拓扑")
    @PreAuthorize("@ss.hasPermi('system:topology:remove')")
    @Log(title = "链路拓扑", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(linkTopologyService.deleteLinkTopologyByIds(ids));
    }
}
